/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package abricots.entity.simulator;

import abricots.entity.BallEntity;
import abricots.command.PlayerCommand;
import abricots.entity.state.BasicEntityState;
import abricots.entity.state.ControllableEntityState;

/**
 *
 * @author charly
 */
public class BallSimulator extends BasicEntitySimulator {
   public BallSimulator(BallEntity ballEntity) {
      super(ballEntity);
   }

   @Override
   protected BasicEntityState applyMovement(BasicEntityState state, int delta) {
      state.setSpeed(0.2f);
      ControllableEntityState ces = (ControllableEntityState) state;
      if (ces.isActionDown()) {
         state.setPosY(state.getPosY() + delta * state.getSpeed());
      }
      if (ces.isActionUp()) {
         state.setPosY(state.getPosY() - delta * state.getSpeed());
      }
      if (ces.isActionLeft()) {
         state.setPosX(state.getPosX() - delta * state.getSpeed());
      }
      if (ces.isActionRight()) {
         state.setPosX(state.getPosX() + delta * state.getSpeed());
      }
      return state;
   }

   @Override
   protected BasicEntityState applyCommand(BasicEntityState state, PlayerCommand command) {
      if (command == null) {
         return state;
      }
      ControllableEntityState ces = (ControllableEntityState) state;
      switch (command.getCommandId()) {
         case PlayerCommand.CMD_UP:
            ces.setActionUp(command.getStarted());
            break;
         case PlayerCommand.CMD_DOWN:
            ces.setActionDown(command.getStarted());
            break;
         case PlayerCommand.CMD_LEFT:
            ces.setActionLeft(command.getStarted());
            break;
         case PlayerCommand.CMD_RIGHT:
            ces.setActionRight(command.getStarted());
            break;
      }
      return ces;
   }
}
